/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("yjy_whole_cost_template",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.Finance.IServices;
using System.Net;
using VOL.Core.Utilities;
using VOL.Core.DBManager;
using System.Linq;

namespace VOL.Finance.Controllers
{
    public partial class yjy_whole_cost_templateController
    {
        private readonly Iyjy_whole_cost_templateService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public yjy_whole_cost_templateController(
            Iyjy_whole_cost_templateService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        public override ActionResult Del([FromBody] object[] keys)
        {
            WebResponseContent webResponse = new WebResponseContent();
            if (keys == null)
            {
                return Json(webResponse.Error("参数不能为空,请重新操作！"));
            }
            string yjy_whole_temp_ids = "";
            foreach (var item in keys)
            {
                yjy_whole_temp_ids = yjy_whole_temp_ids + "'" + item + "',";
            }
            yjy_whole_temp_ids = yjy_whole_temp_ids.Substring(0, yjy_whole_temp_ids.Length - 1);
            string sql = "SELECT ywct.yjy_whole_cost_template_id,ywct.unique_value FROM yjy_whole_cost_template ywct INNER JOIN yjy_whole_cost ywc ON ywct.unique_value = ywc.unique_value WHERE ywct.yjy_whole_cost_template_id IN (" + yjy_whole_temp_ids + ")";
            List<dynamic> list = DBServerProvider.SqlDapper.QueryList<dynamic>(sql, null).ToList();
            if (list!=null && list.Count>0)
            {
                return Json(webResponse.Error("模板数据正在被使用，不能删除！"));
            }
            return base.Del(keys);
        }
    }
}
